package com.xinguan.system.controller;


import com.xinguan.handler.BusinessException;
import com.xinguan.responce.Result;
import com.xinguan.responce.ResultCode;
import com.xinguan.system.entity.TbUser;
import com.xinguan.system.service.TbUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author zzq
 * @since 2021-01-31
 */
@RestController
@RequestMapping("/system/tb-user")
@Api(value = "系统用户模块",tags = "系统用户接口")
public class TbUserController {
    @Autowired
    private TbUserService tbUserService;
    @GetMapping
    @ApiOperation(value="用户列表",notes = "查询所有用户信息")
    public Result findUsers(){

        List<TbUser> list =tbUserService.list();
        return Result.ok().data("users",list);
    }
    @GetMapping("/{id}")
    @ApiOperation(value="用户详信",notes = "用户个人信息查询")
    public Result findByIdUser(@PathVariable("id") Long id) {
        TbUser user=tbUserService.getById(id);
        if (user!=null){
            return Result.ok().data("user",user);
        }
        else {
            throw new BusinessException(ResultCode.USER_NOT_FOUND_EXCEPTION.getCode(),ResultCode.USER_NOT_FOUND_EXCEPTION.getMessage());
        }
    }
}

